home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / dtype / xpkdt10b.lha / Src / classbase.c next >
C/C++ Source or Header  |  1995-11-21  |  4KB  |  125 lines

  1. /*
  2. **    classbase.c - implementation of standard function for XPK DataType class
  3. **    Copyright © 1995 Michael Letowski
  4. */
  5.  
  6. #include <exec/types.h>
  7. #include <exec/execbase.h>
  8. #include <dos/dos.h>
  9. #include <support/types.h>
  10.  
  11. #include <proto/exec.h>
  12. #include <proto/intuition.h>
  13.  
  14. #include "classbase.h"
  15. #include "dispatch.h"
  16.  
  17.  
  18. /*
  19. **    Private constants
  20. */
  21. #define INT_NAME        "intuition.library"
  22. #define INT_VERN        39
  23. #define DOS_NAME        "dos.library"
  24. #define DOS_VERN        39
  25. #define UTIL_NAME        "utility.library"
  26. #define UTIL_VERN        39
  27. #define DT_NAME            "datatypes.library"
  28. #define DT_VERN            39
  29. #define XPK_NAME        "xpkmaster.library"
  30. #define XPK_VERN        0
  31.  
  32.  
  33. /*
  34. **    Public functions
  35. */
  36. ASM Class *ObtainEngine(R_A6 struct ClassBase *cb)
  37. {
  38.     return(cb->cb_Class);
  39. }    /* ObtainEngine */
  40.  
  41. ASM struct ClassBase *LibInit(R_D0 struct ClassBase *cb, R_A0 BPTR segList,
  42.                                                             R_A6 struct Library *sysBase)
  43. {
  44.     cb->cb_SegList=segList;
  45.     cb->cb_SysBase=(struct ExecBase *)sysBase;
  46.  
  47.     InitSemaphore(&cb->cb_Lock);                                    /* Initialize locking */
  48.  
  49.     try(cb->cb_IntuitionBase=    OpenLibrary(INT_NAME,INT_VERN),        NO_INT);
  50.     try(cb->cb_DOSBase=                OpenLibrary(DOS_NAME,DOS_VERN),        NO_DOS);
  51.     try(cb->cb_UtilityBase=        OpenLibrary(UTIL_NAME,UTIL_VERN),    NO_UTIL);
  52.     return(cb);
  53.  
  54.     /* Exceptions */
  55.     catch(FOO,            );
  56.     catch(NO_UTIL,    CloseLibrary(cb->cb_UtilityBase));
  57.     catch(NO_DOS,        CloseLibrary(cb->cb_DOSBase));
  58.     catch(NO_INT,        CloseLibrary(cb->cb_IntuitionBase));
  59.     return(NULL);
  60. }    /* LibInit */
  61.  
  62. ASM struct ClassBase *LibOpen(R_A6 struct ClassBase *cb)
  63. {
  64.     ObtainSemaphore(&cb->cb_Lock);                                /* Protect library base */
  65.     fclr(cb->cb_Lib.lib_Flags,LIBF_DELEXP);                /* No delayed expunge */
  66.  
  67.     if(cb->cb_Lib.lib_OpenCnt==0 && cb->cb_Class==NULL)
  68.     {                                                                                            /* First open */
  69.         try(cb->cb_DataTypesBase=        OpenLibrary(DT_NAME,DT_VERN),        NO_DT);
  70.         try(cb->cb_XpkBase=                    OpenLibrary(XPK_NAME,XPK_VERN),    NO_XPK);
  71.         try(cb->cb_Class=InitClass(cb),                                                            NO_CLASS);
  72.     }
  73.  
  74.     cb->cb_Lib.lib_OpenCnt++;                                            /* Mark successfull opening */
  75.     ReleaseSemaphore(&cb->cb_Lock);                                /* Data modified */
  76.     return(cb);                                                                        /* Return success */
  77.  
  78.     /* Exceptions */
  79.     catch(FOO,            );
  80.     catch(NO_CLASS,    FreeClass(cb->cb_Class));
  81.     catch(NO_XPK,        CloseLibrary(cb->cb_XpkBase));
  82.     catch(NO_DT,        CloseLibrary(cb->cb_DataTypesBase));
  83.     ReleaseSemaphore(&cb->cb_Lock);                                /* Unlock base */
  84.     return(NULL);                                                                    /* Return failure */
  85. }    /* LibOpen */
  86.  
  87. ASM BPTR LibClose(R_A6 struct ClassBase *cb)
  88. {
  89.     BPTR Seg=0;
  90.  
  91.     ObtainSemaphore(&cb->cb_Lock);                                /* Protect library base */
  92.     if(cb->cb_Lib.lib_OpenCnt)
  93.         cb->cb_Lib.lib_OpenCnt--;                                        /* Decrease open count */
  94.     if(cb->cb_Lib.lib_OpenCnt==0 && cb->cb_Class)
  95.         if(FreeClass(cb->cb_Class))
  96.         {
  97.             cb->cb_Class=NULL;
  98.             CloseLibrary(cb->cb_XpkBase);
  99.             CloseLibrary(cb->cb_DataTypesBase);
  100.         }
  101.         else
  102.             fset(cb->cb_Lib.lib_Flags,LIBF_DELEXP);
  103.     ReleaseSemaphore(&cb->cb_Lock);                                /* Unlock base */
  104.     if(ftst(cb->cb_Lib.lib_Flags,LIBF_DELEXP))        /* Delayed expunge set? */
  105.         Seg=LibExpunge(cb);
  106.     return(Seg);
  107. }    /* LibClose */
  108.  
  109. ASM BPTR LibExpunge(R_A6 struct ClassBase *cb)
  110. {
  111.     BPTR Seg=0;
  112.  
  113.     if(cb->cb_Class==NULL)                                                /* No accesors? */
  114.     {
  115.         Seg=cb->cb_SegList;
  116.         Remove((struct Node *)cb);                                    /* Remove from library list */
  117.         CloseLibrary(cb->cb_UtilityBase);
  118.         CloseLibrary(cb->cb_DOSBase);
  119.         CloseLibrary(cb->cb_IntuitionBase);
  120.         FreeMem((APTR)((ULONG)(cb)-(ULONG)(cb->cb_Lib.lib_NegSize)),
  121.                         cb->cb_Lib.lib_NegSize + cb->cb_Lib.lib_PosSize);
  122.     }
  123.     return(Seg);
  124. }    /* LibExpunge */
  125.